import { message } from 'antd';
import { homeData } from '../services/homePage';

export default {
  namespace: 'homePage',

  // 状态机
  state: {
    homeData: {},
  },

  // 发起网络请求
  effects: {
    *home({ payload }, { call, put }) {
      const response = yield call(homeData, payload);
      yield put({ type: 'callbackHome', response });
    },
  },

  // 回调处理
  reducers: {
    callbackHome(st, { response }) {
      const state = st;
      if (response) {
        state.homeData = response;
      } else if (response.status === 1) message.error(response.msg);
      return { ...state };
    },
  },
};
